#include "clcomidfactory.h"
#include <QMutex>
#include <QDateTime>
#include <QThread>

using namespace std;

static QMutex s_lock;
static qint64 s_lastTicks = 0;

CLComIDFactory::CLComIDFactory()
{
}
std::string CLComIDFactory::CreateID(std::string key)
{
    string idstr = key;

    s_lock.lock();

    while (true)
    {
        qint64 ticks = QDateTime::currentMSecsSinceEpoch();

        if (ticks == s_lastTicks)
        {
            QThread::msleep(1);
            continue;
        }
        s_lastTicks = ticks;
        idstr += QString("%1").arg(ticks).toLatin1().data();
        break;
    }

    s_lock.unlock();

    return idstr;
}
